/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * StateGraphBox.java
 *
 * Created on 2011-05-26, 20:59:07
 */
package gisgraph;

import edu.uci.ics.jung.algorithms.layout.FRLayout;
import edu.uci.ics.jung.algorithms.layout.FRLayout2;
import edu.uci.ics.jung.algorithms.layout.KKLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.DirectedSparseGraph;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position;
import gisgraph.components.GISEdge;
import gisgraph.components.StateVertex;
import java.awt.BorderLayout;
import java.awt.Dimension;

/**
 *
 * @author Slawek
 */
public class StateGraphBox extends javax.swing.JDialog {
    
    /** Creates new form StateGraphBox */
    public StateGraphBox(java.awt.Frame parent, 
                                boolean modal, 
                                DirectedSparseGraph<StateVertex, GISEdge> graph) {
        super(parent, modal);
        initComponents();

        Layout<StateVertex, GISEdge> layout = new FRLayout<StateVertex, GISEdge>(graph);
        layout.setSize(new Dimension(550, 450)); // sets the initial size of the space   
        
        
        DefaultModalGraphMouse mouse = new DefaultModalGraphMouse();
        mouse.setMode(Mode.TRANSFORMING);

        
        VisualizationViewer vv = new VisualizationViewer<StateVertex, GISEdge>(layout);
        
        vv.setGraphMouse(mouse);
        vv.setPreferredSize(new Dimension(450, 450));

        // etykieta wierzchołka
        vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
        vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());

        vv.getRenderer().getVertexLabelRenderer().setPosition(Position.S);

        this.getContentPane().add(vv, BorderLayout.CENTER);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(400, 400));
        setName("Form"); // NOI18N

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
